<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- <style>
    th{border-bottom: tomato 2px solid;}
    td{border-bottom: tomato 2px solid;}
</style>
<body>
    <table style="width: 300px; ">
        <tr>
            <th><input type="checkbox" class="a1" onclick="clickChooseAllInput()"></th>
            <th>日期</th>
            <th>姓名</th>
            <th>地址</th>
        </tr>
        <tr>
            <td><input type="checkbox" class="a2"></td>
            <td>2022-3-18</td>
            <td>张三</td>
            <td>郑州</td>
        </tr>
        <tr>
            <td><input type="checkbox" class="a2"></td>
            <td>2022-3-18</td>
            <td>张三</td>
            <td>郑州</td>
        </tr>
        <tr>
            <td><input type="checkbox" class="a2"></td>
            <td>2022-3-18</td>
            <td>张三</td>
            <td>郑州</td>
        </tr>
    </table>
    <button onclick="clickChooseAllBtn()">全选</button>
    <button onclick="clickChooseReverse()">反选</button>
</body>
<script type="text/javascript">
    var chooseAllInputEle = document.getElementsByClassName("a1")[0];
    var chooseSingleEles = document.getElementsByClassName("a2");

    function clickChooseAllInput() {
        if (chooseAllInputEle.checked) {
            choose("selected");
        } else {
            choose("");
        }
    }

    function clickChooseAllBtn() {
        chooseAllInputEle.checked = "checked";
        choose("selected");
    }

    function choose(status) {
        for (var i = 0; i < chooseSingleEles.length; i++) {
            chooseSingleEles[i].checked = status;
        }
    }

    function clickChooseReverse() {
        for (var i = 0; i < chooseSingleEles.length; i++) {
            if (chooseSingleEles[i].checked) {
                chooseSingleEles[i].checked = "";
            } else {
                chooseSingleEles[i].checked = "checked";
            }
        }
    }
</script> -->

</html>